/**
 * 泛娱区块链 - Mine
 * http://menger.me
 * @大梦
 */


'use strict';

import React, { Component } from 'react'
import { StyleSheet, Text, View, WebView } from 'react-native'
import NavigationBar from '../../component/navigation/NavigationBar'
import SpinnerLoading from "../../component/common/SpinnerLoading";



export default class Quotation extends React.PureComponent {

    constructor(props) {
        super(props);
        this.state = {
            uri: 'https://widget.lianxueqiu.com/market?apikey=0a1f055b8f26f6fd&ccy=CNY&theme=light',
            ready: false,
        };
    }

    componentDidMount() {
        this.requestDataSources();
    }

    componentWillMount() {
        this.timer && clearTimeout(this.timer);
    }

    requestDataSources = async () => {
        this.timer = setTimeout(() => this.setState({ready: true}), 500);
    };

    _onPressBack = () => {
        this._webViewRef.goBack()
    };

    _captureRef = (node) => {
        if (node) {
            this._webViewRef = node
        }
    };

    render() {
        let { uri, ready } = this.state;
        return (
            <View style={styles.container}>
                <NavigationBar
                    title={'行情'}
                    onPressBack={this._onPressBack}
                />
                <WebView
                    ref={this._captureRef}
                    style={styles.webView}
                    source={{ uri: uri }}
                />
                <SpinnerLoading isVisible={!ready}/>
            </View>
        );
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
    },
    line: {
        height: 6,
        backgroundColor: '#f5f5f5'
    },
    webView: {
        flex: 1,
    }
});